<template>
  <div class="modal-overlay" @click.self="$emit('close')">
    <div class="modal-content">
      <div class="modal-header">
        <div class="header-item">文件名称</div>
        <div class="header-item">状态</div>
        <div class="header-item">创建时间</div>
        <div class="header-item">操作</div>
      </div>
      <div class="modal-body">
        <div class="file-item" v-for="(file, index) in files" :key="index">
          <div class="file-info name">{{ file.name }}</div>
          <div class="file-info status">{{ file.status }}</div>
          <div class="file-info time">{{ file.time }}</div>
          <div class="file-info action">
            <button class="delete-btn" @click="removeFile(index)">删除</button>
          </div>
        </div>
        <div v-if="files.length === 0" class="empty-list">
          <p>暂无文件</p>
        </div>
      </div>
      <div class="modal-footer">
        <button class="upload-btn" @click="triggerFileInput">上传文件</button>
        <input type="file" ref="fileInput" @change="handleFileUpload" multiple style="display: none;" />
      </div>
    </div>
  </div>
</template>

<script>
import { ref } from 'vue';

export default {
  name: 'MultiUploadModal',
  emits: ['close'],
  setup() {
    const files = ref([
      { name: '鲁抗医药SS-10-2项目.docx', status: '', time: '2024-12-24 23:12:00' },
      { name: 'SS-16项目变压器采购.docx', status: '', time: '' },
      { name: '兰州二期项目干式变压器.docx', status: '异常', time: '2024-12-24 24:27:02' },
      { name: '我是一段很长的标题很长.docx', status: '上传成功', time: '2024-12-24 24:27:02' },
    ]);
    const fileInput = ref(null);

    const triggerFileInput = () => {
      fileInput.value.click();
    };

    const handleFileUpload = (event) => {
      const newFiles = Array.from(event.target.files);
      newFiles.forEach(file => {
        files.value.push({
          name: file.name,
          status: '待上传',
          time: new Date().toLocaleString('sv-SE').replace('T', ' '),
        });
      });
      // Reset file input
      event.target.value = '';
    };

    const removeFile = (index) => {
      files.value.splice(index, 1);
    };

    return {
      files,
      fileInput,
      triggerFileInput,
      handleFileUpload,
      removeFile
    };
  }
};
</script>

<style scoped>
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background-color: white;
  border-radius: 15px;
  width: 80%;
  max-width: 900px;
  height: 70%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  padding: 15px 30px;
  border-bottom: 1px solid #eee;
  font-weight: bold;
  color: #333;
}

.header-item {
  flex-basis: 25%;
  text-align: left;
}

.modal-body {
  flex-grow: 1;
  overflow-y: auto;
  padding: 0 30px;
}

.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 0;
  border-bottom: 1px solid #eee;
}

.file-info {
  flex-basis: 25%;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.name {
  color: #409EFF;
  cursor: pointer;
}

.delete-btn {
  color: #F56C6C;
  background: none;
  border: none;
  cursor: pointer;
}

.empty-list {
  text-align: center;
  padding: 50px;
  color: #909399;
}

.modal-footer {
  padding: 20px 30px;
  text-align: left;
  border-top: 1px solid #eee;
}

.upload-btn {
  background-color: #f0f0f0;
  border: 1px solid #ddd;
  border-radius: 20px;
  padding: 10px 25px;
  font-size: 16px;
  cursor: pointer;
}
</style> 